package davidlauzon.activerecord.nodes;


import davidlauzon.activerecord.visitor.SqlSerializer;

public class SelectStatement extends SqlStatement
{
    /*********************************************************************************************
     * VARIABLES
     *********************************************************************************************/
    private AliasableColumnIF[] _selectColumns;
    private AliasableColumnIF[] _groupByColumns;
    private SortableColumnIF[]  _orderByColumns;
    private AliasableTableIF[]  _selectTables;
    private boolean      _distinct;
    private WhereClause  _where;
    private WhereClause  _having; // FIXME: todo
    private Object[]     _joins;  // FIXME: todo
    private int _limit;
    private long _offset;
    private boolean _count;
    private Function _aggregateFunction = null;
    
    
    /*********************************************************************************************
     * SIMPLE GETTER & SETTERS
     *********************************************************************************************/
    public AliasableTableIF[]  selectTables()  { return _selectTables; }
    public AliasableColumnIF[] selectColumns() { return _selectColumns; }
    public AliasableColumnIF[] groupColumns()  { return _groupByColumns; }
    public SortableColumnIF[]  orderColumns()  { return _orderByColumns; }
    public boolean             isDistinct()    { return _distinct; }
    public WhereClause         whereClause()   { return _where; }
    public int                 limit()         { return _limit; }
    public long                offset()        { return _offset; }
    public boolean             isCount()       { return _count; }
    public boolean  isAggregateFunction()      { return _aggregateFunction != null; }
    public Function aggregateFunction()        { return _aggregateFunction; }
    
    
    
    /*********************************************************************************************
     * PUBLIC METHODS
     *********************************************************************************************/
    public SelectStatement() {
        super();
    }
    
    public void setSelectTables(AliasableTableIF[] tables)    { _selectTables = tables; }
    public void setDistinct(boolean value)                    { _distinct = value; }
    public void setSelectColumns(AliasableColumnIF[] columns) { _selectColumns = columns; }
    public void setWhereClause(WhereClause where)             { _where = where; }
    public void setGroupColumns(AliasableColumnIF[] columns)  { _groupByColumns = columns; }
    public void setOrderColumns(SortableColumnIF[] columns)   { _orderByColumns = columns; }
    public void setLimit( int limit )                         { _limit = limit; }
    public void setOffset( long offset )                      { _offset = offset; }
    public void setCount( boolean value )                     { _count = value; }
    public void setAggregateFunction(Function function)       { _aggregateFunction = function; }
    
    
    @Override
    public String accept(SqlSerializer visitor) {
        return visitor.visit( this );
    }
}
